/* 用户的头像上传 */
const imgEle = document.getElementById("imgEle")
const inpEle = document.getElementById("inpEle")
inpEle.onchange = function () {
    // console.dir(inpELe.files[0].name)
    const filename = inpEle.files[0].name;
    if (!filename.endsWith("jpg")) return alert("请上传jpg格式的图片")

    const formEle = document.getElementById("formEle")
    const fm = new FormData(formEle);

    //校验之后,打算上传
    const xhr = new XMLHttpRequest()
    xhr.open("post", "http://localhost:8080/admin/upload/file")
    xhr.send(fm)
    xhr.onload = function () {
        const res = JSON.parse(xhr.responseText)
        if (res.code == 200) {
            // console.log(res.msg);
            imgEle.src = res.msg;
        }
    }
}